From d4c6b81a80d13f84b037096e7a6570d2305fe1fe Mon Sep 17 00:00:00 2001 From: tsteven4 Date: Tue, 13 Nov 2018 07:59:10 -0700 Subject: [PATCH] fix clazy detected 'allocating an unneeded temporary container' these are from -Wclazy-container-anti-pattern Also, consistently use range based for loops in csv_util.cc --- csv_util.cc | 4 ++-- mmo.cc | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/csv_util.cc b/csv_util.cc index 034e34a34..fb7d1f403 100644 --- a/csv_util.cc +++ b/csv_util.cc @@ -24,7 +24,7 @@ #include // for QDateTime, QDate #include // for QString, QCharRef #include // for QTextStream -#include // for foreach +#include // for qAsConst #include "csv_util.h" #include "defs.h" @@ -1421,7 +1421,7 @@ xcsv_data_read(void) * pre-read the file to know how many data lines we should be seeing, * we take this cheap shot at the data and cross our fingers. */ - foreach(const QString& ogp, xcsv_file.epilogue) { + for(const auto& ogp : qAsConst(xcsv_file.epilogue)) { if (ogp.startsWith(buff)) { buff.clear(); break; diff --git a/mmo.cc b/mmo.cc index 2c55cd63d..f211e8cf9 100644 --- a/mmo.cc +++ b/mmo.cc @@ -22,6 +22,7 @@ #include "defs.h" #include +#include #include #include #include @@ -259,9 +260,9 @@ mmo_register_object(const int objid, const void* ptr, const gpsdata_type type) static int mmo_get_objid(const void* ptr) { - foreach(int key, objects.keys()) { - if (objects.value(key)->data == ptr) { - return key; + for (auto o = objects.constBegin(); o != objects.constEnd(); ++o) { + if (o.value()->data == ptr) { + return o.key(); } } return 0; @@ -305,7 +306,7 @@ mmo_free_object(mmo_data_t* data) xfree(data->name); } if ((data->type == wptdata) && (data->refct == 0)) { - delete(Waypoint*)data->data; + delete (Waypoint*)data->data; } xfree(data); } @@ -973,8 +974,8 @@ mmo_rd_deinit() icons.clear(); - foreach(int k, objects.keys()) { - mmo_free_object(objects.value(k)); + for (auto value : qAsConst(objects)) { + mmo_free_object(value); } objects.clear(); @@ -1279,7 +1280,7 @@ mmo_write_rte_head_cb(const route_head* rte) mmo_rte = rte; QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) { - Waypoint* wpt = reinterpret_cast(elem); + Waypoint* wpt = reinterpret_cast(elem); QDateTime t = wpt->GetCreationTime(); if ((t.isValid()) && (t.toTime_t() < time)) { time = t.toTime_t(); @@ -1323,7 +1324,7 @@ mmo_write_rte_tail_cb(const route_head* rte) } QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) { - Waypoint* wpt = reinterpret_cast(elem); + Waypoint* wpt = reinterpret_cast(elem); int objid = mmo_get_objid(wpt); gbfputuint16(objid & 0x7FFF, fout); } @@ -1409,8 +1410,8 @@ mmo_wr_deinit() mmobjects.clear(); category_names.clear(); - foreach(int k, objects.keys()) { - mmo_free_object(objects.value(k)); + for (auto value : qAsConst(objects)) { + mmo_free_object(value); } objects.clear(); -- 2.30.2